package com.tj.api.rest;

import com.alibaba.fastjson.JSONObject;
import com.fqgj.base.services.redis.RedisClient;
import com.fqgj.common.utils.DES;
import com.tj.api.annotations.SignIgnore;
import com.tj.api.annotations.VisitorAccessible;
import com.tj.bo.common.conf.config.FileConfigUtil;
import com.tj.bo.common.conf.constant.RedisKey;
import com.tj.bo.user.client.UserPromotionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * User: binary (mr.vencnet@gmail.com)
 * Date: 2020-06-02
 * Time: 17:18
 */
@RestController
public class OkController {

    private static final Logger LOGGER = LoggerFactory.getLogger(OkController.class);

    @Autowired
    private RedisClient redisClient;

    @Autowired
    private FileConfigUtil fileConfigUtil;

    @Autowired
    private UserPromotionService userPromotionService;

    @SignIgnore
    @RequestMapping("/ok")
    public String ok() {
        return "ok";
    }


    @SignIgnore
    @RequestMapping("/ok2")
    public String ok2() {
//        redisClient.set(RedisKey.BINARY_OPTION_PRODUCT_CACHE_KEY, "");
        return "this is binary api,ok";
    }

    @SignIgnore
    @RequestMapping("/charge/ok")
    public String charge() {
        return "ok";
    }

    @SignIgnore
    @RequestMapping("/logok")
    @ResponseBody
    public String logok() {
        LOGGER.info("testok,AAA111111222222333333," + fileConfigUtil.isServerTest());
        return "logok";
    }

    @SignIgnore
    @VisitorAccessible
    @RequestMapping(value = "/deleteCache/{userCode}/{productCode}", method = RequestMethod.GET)
    public String deleteCache(@PathVariable("userCode") String userCode, @PathVariable("productCode") String productCode) {
        redisClient.del(RedisKey.BINARY_OPTION_PRODUCT_CACHE_KEY);
        redisClient.del(RedisKey.BINARY_OPTION_PRODUCT_ODDS_CONFIG_KEY);
        redisClient.del(RedisKey.BINARY_OPTION_PRODUCT_USER_ODDS, productCode, userCode);
        redisClient.del(RedisKey.BINARY_OPTION_HAS_DEPOSIT_RECORD, userCode);
        return "deleteCache success";
    }


    @SignIgnore
    @RequestMapping("/generateInviteCode")
    @ResponseBody
    public String generateInviteCode() {
        int sum = userPromotionService.createPromotionHistoryFromTableInTask();
        return "generateInviteCode total [" + sum + "] person";
    }


    public static void main(String[] args) {

        try {
            String password = "Qq12哈哈哈哈哈哈3123+-a1...1234567890";
            String s1 = DES.encrypt(password);
            System.out.println(s1);
            System.out.println(DES.encrypt(password));
            System.out.println(DES.encrypt(password));
            System.out.println(DES.encrypt(password));
            System.out.println(DES.encrypt(password));
            System.out.println(DES.encrypt(password));
            String s2 = DES.decrypt(s1);
            System.out.println(s2);
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            System.out.println(DES.decrypt("tdVqEV8+9ld22NEf6iqks1/jEK2JMD9ifuR0fmVSBD8="));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @SignIgnore
    @VisitorAccessible
    @RequestMapping(value = "/moveData/{type}", method = RequestMethod.GET)
    public String moveData(@PathVariable("type") Integer type) {

        return "moveData success";
    }

}
